﻿using System.Collections.Generic;
using Nissen_Dao;
using Nissen_Model;

namespace Nissen_Manage.Forms
{
	public class TestService
	{

		public IList<Test> GetTests()
		{
			TestDao testDao = new TestDao();
			return testDao.GetTests();

		}

		public IList<Test> GetShowTests()
		{
			TestDao testDao = new TestDao();
			return testDao.GetShowTests();

		}

		public void SaveTests(IList<Test> tests)
		{
			TestDao testDao = new TestDao();

			testDao.SaveOrUpdateTests(tests);

			TestMapDao testMapDao = new TestMapDao();

			IList<TestMap> dbTestMaps = testMapDao.GetTestMaps();

			IList<TestMap> testMaps = new List<TestMap>();

			IList<string> dbTestId = new List<string>();
			foreach (var dbTestMap in dbTestMaps)
			{
				dbTestId.Add(dbTestMap.TestCode);
			}

			foreach (var test in tests)
			{
				if(dbTestId.Contains(test.TestId))
				{
					continue;
				}
				TestMap testMap =new TestMap();
				testMap.TestCode = test.TestId;
				testMap.TestName = test.TestName;
				testMaps.Add(testMap);
			}
			testMapDao.SaveOrUpdate(testMaps);
		}
	}
}
